package com.test.ayi.test.competablefuture;

import java.util.concurrent.CompletableFuture;

import static java.lang.Thread.sleep;

public class CFtest5AnyOne {
    public static void main(String[] args) throws InterruptedException {

        CompletableFuture<String> potA = CompletableFuture.supplyAsync(() -> {
            try {
                sleep(2000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            return "番茄锅";
        });
        CompletableFuture<String> potB = CompletableFuture.supplyAsync(() -> {
            try {
                sleep(1000);
                int i = 1/0;
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            return "菌汤锅";
        }).exceptionally(e -> "豆汤锅222🤗🤗🤗");

        CompletableFuture<Object> winner =
                CompletableFuture.anyOf(potA, potB); // 谁快谁赢

        System.out.println(winner.join()); // 大概率：菌汤锅


    }
}
